/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright 2009 - 2012 Luca Mingardi.
 *
 * This file is part of jeeObserver.
 *
 * JeeObserver is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * JeeObserver is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */
package jeeobserver.server.settings;

import jeeobserver.HttpSessionObserver;
import jeeobserver.utilities.TimeUtilities;

/**
 * The Class HttpSessionNotificationRule.
 *
 * @author Luca Mingardi
 * @version 4.0
 */
public final class HttpSessionNotificationRule extends HttpSessionExclusionRule {

	 /** The Constant serialVersionUID. */
	 private static final long serialVersionUID = 40L;

	 /** The Constant TAG_CODE_CONTEXT. */
	 public static final String TAG_CODE_CONTEXT = "{context}";

	 /** The Constant TAG_CODE_PROJECT. */
	 public static final String TAG_CODE_PROJECT = "{project}";

	 /** The Constant TAG_CODE_SESSION_ID. */
	 public static final String TAG_CODE_SESSION_ID = "{session_id}";

	 /** The Constant TAG_CODE_START_TIMESTAMP. */
	 public static final String TAG_CODE_START_TIMESTAMP = "{start_timestamp}";

	 /** The Constant TAG_CODE_TIME_NANOS. */
	 public static final String TAG_CODE_TIME_NANOS = "{time_nanos}";

	 /** The Constant TAG_CODE_TIME_FORMATTED. */
	 public static final String TAG_CODE_TIME_FORMATTED = "{time_formatted}";

	 /** The notification. */
	 private Notification notification;

	 /**
	  * Instantiates a new http session notification rule.
	  *
	  * @param notification the notification
	  */
	 public HttpSessionNotificationRule(Notification notification) {
			this.notification = notification;
	 }

	 /**
	  * Gets the notification.
	  *
	  * @param observer the http session observer
	  *
	  * @return the notification
	  */
	 public Notification getNotification(HttpSessionObserver observer) {

			if (observer != null) {
				 this.notification.setTag(HttpSessionNotificationRule.TAG_CODE_CONTEXT, observer.getContext());
				 this.notification.setTag(HttpSessionNotificationRule.TAG_CODE_PROJECT, observer.getProject());
				 this.notification.setTag(HttpSessionNotificationRule.TAG_CODE_START_TIMESTAMP, observer.getDate());

				 this.notification.setTag(HttpSessionNotificationRule.TAG_CODE_TIME_NANOS, observer.getTimeNanos());
				 this.notification.setTag(HttpSessionNotificationRule.TAG_CODE_TIME_FORMATTED, TimeUtilities.fromNanosToString(observer.getTimeNanos()));
			}
			return this.notification;
	 }

	 /**
	  * Gets the notification.
	  *
	  * @return the notification
	  */
	 public Notification getNotification() {
			return this.notification;
	 }

	 /**
	  * Sets the notification.
	  *
	  * @param notification the new notification
	  */
	 public void setNotification(Notification notification) {
			this.notification = notification;
	 }
}
